// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/order/api/AppWorkOrderApi'

import EditClass from '@api/order/model/AppAddWorkOrderEventReq'
import BaseClass from '@api/order/model/AppWorkOrderEventDto'
import FileClass from '@api/order/model/AppWorkOrderEventFileDto'
import OrderClass from '@api/order/model/AppWorkOrderDto'
import BackupClass from '@api/order/model/AppWorkOrderPreAssetDto'

const CLIENT = CORE.grpcCLIENT(Client)
const FILE = [FileClass, 'workOrderEventFileDto']
const BACKUP = [BackupClass, 'workOrderPreAssetDto', 1]
const ORDER = [OrderClass, 'workOrderDto', 'repair', (dto, obj) => CORE.grpcDTO(dto, obj, BACKUP)]

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 修改 —————————————————————————————— //

  async edit(one, TIP = '修改') {
    const imageList = one.image.map((fileUrl) => ({ fileUrl, fileName: fileUrl.split('/').pop(), fileType: 1 }))
    const BASE = [BaseClass, 'workOrderEventDto', '', (dto, obj) => {
      CORE.grpcDTO(dto, obj, [...FILE, imageList])
    }]
    const DTO = CORE.grpcDTO(EditClass, one, BASE, ORDER)
    await CORE.grpc(TIP, CLIENT, `${one.method}AppTask`, DTO)
    return CORE.grpcOK(TIP)
  },
}
